package androidx.appcompat.view.menu;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView.SelectionBoundsAdjuster;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.core.view.ViewCompat;
import o.ah$i;
import o.ah$j;
import o.ah.c;
import o.ah.g;
import o.bj;
import o.bo.b;
import o.cw;

@RestrictTo({d.LIBRARY_GROUP})
public class ListMenuItemView extends LinearLayout implements b, SelectionBoundsAdjuster {
    private TextView ʻ;
    private int ʻॱ;
    private ImageView ʼ;
    private LinearLayout ʽ;
    private bj ˊ;
    private boolean ˊॱ;
    private TextView ˋ;
    private boolean ˋॱ;
    private ImageView ˎ;
    private CheckBox ˏ;
    private int ˏॱ;
    private Context ͺ;
    private RadioButton ॱ;
    private Drawable ॱˊ;
    private boolean ॱˎ;
    private Drawable ॱॱ;
    private LayoutInflater ॱᐝ;
    private ImageView ᐝ;

    public ListMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.ˎˎ);
    }

    public ListMenuItemView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet);
        cw ॱ = cw.ॱ(getContext(), attributeSet, g.ˉˊ, i, 0);
        this.ॱॱ = ॱ.ˋ(g.ˊˈ);
        this.ˏॱ = ॱ.ॱॱ(g.ˊˉ, -1);
        this.ˋॱ = ॱ.ˋ(g.ˊʿ, false);
        this.ͺ = context;
        this.ॱˊ = ॱ.ˋ(g.ˊʾ);
        TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(null, new int[]{16843049}, c.ˋˊ, 0);
        this.ˊॱ = obtainStyledAttributes.hasValue(0);
        ॱ.ॱ();
        obtainStyledAttributes.recycle();
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        ViewCompat.ˏ(this, this.ॱॱ);
        this.ˋ = (TextView) findViewById(ah$i.ـ);
        if (this.ˏॱ != -1) {
            this.ˋ.setTextAppearance(this.ͺ, this.ˏॱ);
        }
        this.ʻ = (TextView) findViewById(ah$i.ˑ);
        this.ᐝ = (ImageView) findViewById(ah$i.ॱʽ);
        if (this.ᐝ != null) {
            this.ᐝ.setImageDrawable(this.ॱˊ);
        }
        this.ʼ = (ImageView) findViewById(ah$i.ʽॱ);
        this.ʽ = (LinearLayout) findViewById(ah$i.ॱˊ);
    }

    public void ॱ(bj bjVar, int i) {
        this.ˊ = bjVar;
        this.ʻॱ = i;
        setVisibility(bjVar.isVisible() ? 0 : 8);
        setTitle(bjVar.ˏ((b) this));
        setCheckable(bjVar.isCheckable());
        setShortcut(bjVar.ॱॱ(), bjVar.ˎ());
        setIcon(bjVar.getIcon());
        setEnabled(bjVar.isEnabled());
        ॱ(bjVar.hasSubMenu());
        setContentDescription(bjVar.getContentDescription());
    }

    private void ˊ(View view) {
        ˊ(view, -1);
    }

    private void ˊ(View view, int i) {
        if (this.ʽ != null) {
            this.ʽ.addView(view, i);
        } else {
            addView(view, i);
        }
    }

    public void setForceShowIcon(boolean z) {
        this.ॱˎ = z;
        this.ˋॱ = z;
    }

    public void setTitle(CharSequence charSequence) {
        if (charSequence != null) {
            this.ˋ.setText(charSequence);
            if (this.ˋ.getVisibility() != 0) {
                this.ˋ.setVisibility(0);
            }
        } else if (this.ˋ.getVisibility() != 8) {
            this.ˋ.setVisibility(8);
        }
    }

    public bj ˏ() {
        return this.ˊ;
    }

    public void setCheckable(boolean z) {
        if (z || this.ॱ != null || this.ˏ != null) {
            CompoundButton compoundButton;
            CompoundButton compoundButton2;
            if (this.ˊ.ʼ()) {
                if (this.ॱ == null) {
                    ˎ();
                }
                compoundButton = this.ॱ;
                compoundButton2 = this.ˏ;
            } else {
                if (this.ˏ == null) {
                    ˋ();
                }
                compoundButton = this.ˏ;
                compoundButton2 = this.ॱ;
            }
            if (z) {
                compoundButton.setChecked(this.ˊ.isChecked());
                if (compoundButton.getVisibility() != 0) {
                    compoundButton.setVisibility(0);
                }
                if (compoundButton2 != null && compoundButton2.getVisibility() != 8) {
                    compoundButton2.setVisibility(8);
                    return;
                }
                return;
            }
            if (this.ˏ != null) {
                this.ˏ.setVisibility(8);
            }
            if (this.ॱ != null) {
                this.ॱ.setVisibility(8);
            }
        }
    }

    public void setChecked(boolean z) {
        CompoundButton compoundButton;
        if (this.ˊ.ʼ()) {
            if (this.ॱ == null) {
                ˎ();
            }
            compoundButton = this.ॱ;
        } else {
            if (this.ˏ == null) {
                ˋ();
            }
            compoundButton = this.ˏ;
        }
        compoundButton.setChecked(z);
    }

    private void ॱ(boolean z) {
        if (this.ᐝ != null) {
            this.ᐝ.setVisibility(z ? 0 : 8);
        }
    }

    public void setShortcut(boolean z, char c) {
        int i = (z && this.ˊ.ॱॱ()) ? 0 : 8;
        if (i == 0) {
            this.ʻ.setText(this.ˊ.ˏ());
        }
        if (this.ʻ.getVisibility() != i) {
            this.ʻ.setVisibility(i);
        }
    }

    public void setIcon(Drawable drawable) {
        int i = (this.ˊ.ʽ() || this.ॱˎ) ? 1 : 0;
        if (i == 0 && !this.ˋॱ) {
            return;
        }
        if (this.ˎ != null || drawable != null || this.ˋॱ) {
            if (this.ˎ == null) {
                ॱ();
            }
            if (drawable != null || this.ˋॱ) {
                ImageView imageView = this.ˎ;
                if (i == 0) {
                    drawable = null;
                }
                imageView.setImageDrawable(drawable);
                if (this.ˎ.getVisibility() != 0) {
                    this.ˎ.setVisibility(0);
                    return;
                }
                return;
            }
            this.ˎ.setVisibility(8);
        }
    }

    protected void onMeasure(int i, int i2) {
        if (this.ˎ != null && this.ˋॱ) {
            LayoutParams layoutParams = getLayoutParams();
            LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) this.ˎ.getLayoutParams();
            if (layoutParams.height > 0 && layoutParams2.width <= 0) {
                layoutParams2.width = layoutParams.height;
            }
        }
        super.onMeasure(i, i2);
    }

    private void ॱ() {
        this.ˎ = (ImageView) ॱॱ().inflate(ah$j.ˋॱ, this, false);
        ˊ(this.ˎ, 0);
    }

    private void ˎ() {
        this.ॱ = (RadioButton) ॱॱ().inflate(ah$j.ͺ, this, false);
        ˊ(this.ॱ);
    }

    private void ˋ() {
        this.ˏ = (CheckBox) ॱॱ().inflate(ah$j.ʻ, this, false);
        ˊ(this.ˏ);
    }

    public boolean a_() {
        return false;
    }

    private LayoutInflater ॱॱ() {
        if (this.ॱᐝ == null) {
            this.ॱᐝ = LayoutInflater.from(getContext());
        }
        return this.ॱᐝ;
    }

    public void setGroupDividerEnabled(boolean z) {
        if (this.ʼ != null) {
            ImageView imageView = this.ʼ;
            int i = (this.ˊॱ || !z) ? 8 : 0;
            imageView.setVisibility(i);
        }
    }

    public void adjustListItemSelectionBounds(Rect rect) {
        if (this.ʼ != null && this.ʼ.getVisibility() == 0) {
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) this.ʼ.getLayoutParams();
            rect.top = (layoutParams.bottomMargin + (this.ʼ.getHeight() + layoutParams.topMargin)) + rect.top;
        }
    }
}
